<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <link rel="shortcut icon" href="../../static/favicon.ico" th:href="@{/favicon.ico}"/>

    <title>Add Client . OAuth2-Shiro[authz]</title>

    <th:block th:include="fragments/main::header-css"/>
    <style>
        .list-group li:hover {
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
<div class="container">
    <a href="../" th:href="@{/}">Home</a>

    <h2>Add Client</h2>

    <div>
        <p class="help-block">
            这里列出了一个 client_details 需要的所有属性进行添加, 但在实际使用场景中, 许多属性是由系统处理的, 不需要用户关心.
        </p>

        <div>
            <!--            <form:form commandName="formDto" cssClass="form-horizontal">-->
            <form method="post" th:object="${formDto}" action="" class="form-horizontal">
                <div class="form-group">
                    <label for="clientId" class="col-sm-2 control-label">client_id<em class="text-danger">*</em></label>

                    <div class="col-sm-10">
                        <input name="clientId" class="form-control" id="clientId" placeholder="client_id"
                                    required="required" th:field="*{clientId}"/>

                        <p class="help-block">client_id必须输入,且必须唯一,长度至少5位; 在实际应用中的另一个名称叫appKey,与client_id是同一个概念.</p>
                    </div>
                </div>
                <div class="form-group">
                    <label for="clientSecret" class="col-sm-2 control-label">client_secret<em
                            class="text-danger">*</em></label>

                    <div class="col-sm-10">
                        <input name="clientSecret" class="form-control" id="clientSecret"
                                    placeholder="client_secret" required="required" th:field="*{clientSecret}"/>

                        <p class="help-block">client_secret必须输入,且长度至少8位;
                            在实际应用中的另一个名称叫appSecret,与client_secret是同一个概念.</p>
                    </div>
                </div>
                <div class="form-group">
                    <label for="resourceIds" class="col-sm-2 control-label">resource_ids<em
                            class="text-danger">*</em></label>

                    <div class="col-sm-10">
                        <select name="resourceIds" class="form-control" id="resourceIds" th:field="*{resourceIds}">
                            <option value="os-resource">os-resource</option>
                            <option value="mobile-resource">mobile-resource</option>
                        </select>

                        <p class="help-block">resourceIds, 用于定义一组资源的Id, 在[resources]模块中使用,
                            可在[resources]模块的<em>rs-security.xml</em>查看定义的resourceId(每一个 OAuth2Filter 代表一个资源)</p>
                    </div>
                </div>

                <div class="form-group">
                    <label for="scope" class="col-sm-2 control-label">scope<em class="text-danger">*</em></label>

                    <div class="col-sm-10">
                        <select name="scope" id="scope" class="form-control" th:field="*{scope}">
                            <option value="read">read</option>
                            <option value="write">write</option>
                        </select>

                        <p class="help-block">scope必须选择</p>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">grant_type(s)<em class="text-danger">*</em></label>

                    <div class="col-sm-10">
                        <label class="checkbox-inline">
                            <input type="checkbox" name="grantTypes" th:checked="${formDto.grantTypes.contains('authorization_code')}"
                                   value="authorization_code" />
                            authorization_code
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="grantTypes" th:checked="${formDto.grantTypes.contains('password')}"
                                   value="password" />
                            password
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="grantTypes" th:checked="${formDto.grantTypes.contains('client_credentials')}"
                                   value="client_credentials"/>
                            client_credentials
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="grantTypes" th:checked="${formDto.grantTypes.contains('implicit')}"
                                   value="implicit"/>
                            implicit
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="grantTypes" th:checked="${formDto.grantTypes.contains('refresh_token')}"
                                   value="refresh_token"/>
                            refresh_token
                        </label>

                        <p class="help-block">至少勾选一项grant_type(s), 且不能只单独勾选<code>refresh_token</code>, 若需更多帮助请访问 <a
                                href="https://andaily.com/blog/?p=103"
                                target="_blank">https://andaily.com/blog/?p=103</a></p>
                    </div>
                </div>

                <div class="form-group">
                    <label for="redirectUri" class="col-sm-2 control-label">redirect_uri</label>

                    <div class="col-sm-10">
                        <input name="redirectUri" id="redirectUri" placeholder="http://..."
                                    class="form-control" th:field="*{redirectUri}"/>

                        <p class="help-block">若<code>grant_type</code>包括<em>authorization_code</em>,<em>implicit</em>,
                            则必须输入redirect_uri</p>
                    </div>
                </div>

                <div class="form-group">
                    <label for="roles" class="col-sm-2 control-label">roles</label>

                    <div class="col-sm-10">
                        <select name="roles" id="roles" class="form-control" th:field="*{roles}">
                            <option value="">无</option>
                            <option th:each="item : ${formDto.rolesDtoList}" th:value="${item.id}">[[${item.roleName}]]</option>
                        </select>

                        <p class="help-block">指定客户端所拥有的Shiro Role,可选; 尚未使用</p>
                    </div>
                </div>

                <div class="form-group">
                    <label for="accessTokenValidity" class="col-sm-2 control-label">access_token_validity</label>

                    <div class="col-sm-10">
                        <input type="number" class="form-control" name="accessTokenValidity" id="accessTokenValidity"
                               placeholder="access_token_validity" th:field="*{accessTokenValidity}"/>

                        <p class="help-block">设定客户端的access_token的有效时间值(单位:秒),可选, 若不设定值则使用默认的有效时间值(60 * 60 * 12, 12小时);
                            若设定则必须是大于0的整数值</p>
                    </div>
                </div>

                <div class="form-group">
                    <label for="refreshTokenValidity" class="col-sm-2 control-label">refresh_token_validity</label>

                    <div class="col-sm-10">
                        <input type="number" class="form-control" name="refreshTokenValidity" id="refreshTokenValidity"
                               placeholder="refresh_token_validity" th:field="*{refreshTokenValidity}"/>

                        <p class="help-block">设定客户端的refresh_token的有效时间值(单位:秒),可选, 若不设定值则使用默认的有效时间值(60 * 60 * 24 * 30,
                            30天);
                            若设定则必须是大于0的整数值</p>
                    </div>
                </div>

                <div class="form-group">
                    <label for="clientName" class="col-sm-2 control-label">client_name<em
                            class="text-danger">*</em></label>

                    <div class="col-sm-10">
                        <input name="clientName" id="clientName" placeholder="Client名称" class="form-control"
                                    required="required" th:field="*{clientName}"/>

                        <p class="help-block">给Client起一个有意义的名称</p>
                    </div>
                </div>

                <div class="form-group">
                    <label for="clientUri" class="col-sm-2 control-label">client_uri</label>

                    <div class="col-sm-10">
                        <input name="clientUri" id="clientUri" placeholder="http://..." class="form-control" th:field="*{clientUri}"/>

                        <p class="help-block">该Client的URI, 可选</p>
                    </div>
                </div>
                <div class="form-group">
                    <label for="clientIconUri" class="col-sm-2 control-label">client_icon_uri</label>

                    <div class="col-sm-10">
                        <input name="clientIconUri" id="clientIconUri" placeholder="http://..."
                                    class="form-control" th:field="*{clientIconUri}"/>

                        <p class="help-block">该Client的Icon URI, 可选</p>
                    </div>
                </div>

                <div class="form-group">
                    <label for="description" class="col-sm-2 control-label">description</label>

                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="description" id="description"
                               placeholder="Client Description" th:field="*{description}"/>

                        <p class="help-block">Client的描述, 可选</p>
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-sm-2 control-label">trusted</label>

                    <div class="col-sm-10">
                        <label class="radio-inline">
                            <input type="radio" name="trusted" th:value="true" th:field="*{trusted}"/> Yes
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="trusted" th:value="false" th:field="*{trusted}" checked="checked"/> No
                        </label>

                        <p class="help-block">该属性是扩展的,
                            只适用于grant_type(s)包括<code>authorization_code</code>的情况,当用户登录成功后,若选No,则会跳转到让用户Approve的页面让用户同意授权,
                            若选Yes,则在登录后不需要再让用户Approve同意授权(因为是受信任的)</p>
                    </div>
                </div>


                <div class="form-group">
                    <div class="col-sm-2"></div>
                    <div class="col-sm-10">
                        <span th:errors="*" class="label label-warning"></span>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-2"></div>
                    <div class="col-sm-10">
                        <button type="submit" class="btn btn-success">保存</button>
                        <a href="../../client_details">取消</a>
                    </div>
                </div>
            </form>
        </div>


        <div th:replace="fragments/main :: footer"/>
    </div>
</body>
</html>